<html>
  <head>
    <meta charset="utf-8" />
    <title>Box2D</title>
    <!-- <script type="text/javascript" src="../node_modules/systemjs/dist/system.js"></script> -->
    <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/systemjs@0.21.6/dist/system.js"></script>
    <script type="text/javascript">

    function boot(args) {
      const transpile = args.indexOf("transpile") !== -1;
      console.log("transpile", transpile);
      if (transpile) {
        SystemJS.config({
          // map: { "typescript": "../node_modules/typescript", }
          map: { "typescript": "https://cdn.jsdelivr.net/npm/typescript@3.4.5", },
          packages: { "typescript": { main: "lib/typescript.js", meta: { "lib/typescript.js": { exports: "ts" } } } },
        });
        SystemJS.config({
          // map: { "plugin-typescript": "../node_modules/plugin-typescript" },
          map: { "plugin-typescript": "https://cdn.jsdelivr.net/npm/plugin-typescript@8.0.0" },
          packages: { "plugin-typescript": { main: "lib/plugin.js" } },
          transpiler: "plugin-typescript",
          typescriptOptions: { tsconfig: true, module: "system" }
        });
        SystemJS.config({
          map: { "Box2D": "./" },
          packages: { "Box2D": { main: "Box2D.ts", defaultExtension: "ts" } }
        });
      } else {
        SystemJS.config({
          map: { "Box2D": "./" },
          packages: { "Box2D": { main: "Box2D.js", defaultExtension: "js" } }
        });
      }
      System.import("Box2D").then(function(box2d) {
        console.log(box2d.b2_version);
      }).catch(console.error);
    }

    window.addEventListener('load', function(event) {
      const args = window.location.search.substring(1).split('&'); // args from window location
      console.log(args);
      boot(args);
    });

    </script>
  </head>
</html>
